package com.coderush.admin.sys.controller;

import com.coderush.admin.core.response.Result;
import com.coderush.admin.sys.model.dto.MenuAssignDto;
import com.coderush.admin.sys.service.RoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * PackageName com.coderush.admin.sys.controller
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName RoleMenuController
 * @Date 2025/9/4
 * @Description TODO
 */
@RestController
@RequestMapping("/sys/roleMenu")
@Validated  // 类级别添加，用于方法参数校验
@Tag(name = "角色和菜单管理", description = "角色和菜单管理")
public class RoleMenuController {

    @Resource
    private RoleMenuService roleMenuService;

    /**
     * 分配菜单 - 查询
     */
    @Operation(summary = "分配菜单 - 查询", description = "分配菜单 - 查询")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @GetMapping("/findAssignMenu/{roleId}")
    public Result<Map<String, Object>> findAssignMenu(@PathVariable Long roleId) throws Exception {

        Map<String, Object> assignMenu = roleMenuService.findAssignMenu(roleId);

        return Result.buildSuccess(assignMenu);
    }

    /**
     * 角色分配菜单
     */
    @Operation(summary = "角色分配菜单", description = "角色分配菜单")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/assignMenu")
    public Result<Boolean> assignMenu(@RequestBody MenuAssignDto menuAssignDto) throws Exception {

        Boolean assignMenu = roleMenuService.assignMenu(menuAssignDto);

        return Result.buildSuccess(assignMenu);
    }

}